import 'dart:async';

import 'package:flutter/material.dart';
import 'package:shopping_group/base/base_constant.dart';
import 'package:shopping_group/entity/community_seletion_result_entity.dart';
import 'package:shopping_group/entity/widget_entity.dart';
import 'package:shopping_group/modle/person/bloc/bank_list_bloc.dart';
import 'package:shopping_group/utils/utils.dart';
import 'package:shopping_group/utils/widget_utils.dart';
import 'package:shopping_group/view/button_progress_view.dart';

class MoneyYongjinChangePage extends StatefulWidget {
  MoneyYongjinChangePage({
    Key key,
  }) : super(key: key);

  @override
  _MoneyYongjinChangePageState createState() => _MoneyYongjinChangePageState();
}

class _MoneyYongjinChangePageState extends State<MoneyYongjinChangePage> {
  WidgetEntity _zfbWidgetEntity = WidgetEntity();
  List<CommunitySeletionResultEntity> _zfbList = [];
  WidgetEntity _jeWidgetEntity = WidgetEntity();
  BankListBloc _bloc;

  @override
  void initState() {
    super.initState();
    _bloc = BankListBloc();
    _bloc.bankTypeDate.add(null);

    _jeWidgetEntity = WidgetUtils.initEditText(
        '转换金额：', '', '请输入转换金额', 'number', TextEditingController());

    _zfbList
      ..add(CommunitySeletionResultEntity()
        ..name = '代理券'
        ..id = '1')
      ..add(CommunitySeletionResultEntity()
        ..name = '推广费'
        ..id = '2');
    _zfbWidgetEntity = WidgetUtils.initSpinner('金额转换', '', _zfbList, '1');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: WidgetUtils.showAppar(context, '代理券与推广费互转'),
      body: Container(
        decoration: new BoxDecoration(
          color: Colors.white,
        ),
        child: SingleChildScrollView(
          scrollDirection: Axis.vertical,
          reverse: false,
          padding: EdgeInsets.all(0.0),
          physics: BouncingScrollPhysics(),
          child: Column(
            children: <Widget>[
              WidgetUtils.showSpinner(
                _zfbWidgetEntity,
                stateCallback: (date) {
                  setState(() {
                    _zfbWidgetEntity.spinnerValue = date;
                  });
                },
              ),
              WidgetUtils.itmeStyleView(
                  '${_zfbWidgetEntity.spinnerValue}金额',
                  '1' ==
                          Utils.getSpinnerId(_zfbWidgetEntity.spinnerList,
                              _zfbWidgetEntity.spinnerValue)
                      ? BaseConstant.integralAccount
                      : BaseConstant.capitalAccount,
                  bewteenleft: 12),
              WidgetUtils.itmeStyleView(
                  '转换类型',
                  '1' ==
                          Utils.getSpinnerId(_zfbWidgetEntity.spinnerList,
                              _zfbWidgetEntity.spinnerValue)
                      ? '推广费'
                      : '代理券',
                  bewteenleft: 12),
              // Container(
              //   alignment: Alignment.center,
              //   padding:
              //       const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
              //   child: WidgetUtils.getTextColorView(
              //     '请务必确认账号准确性，一经转账，无法退回',
              //     Colours.red_606,
              //     Dimens.FONT_SIZE_13,
              //   ),
              // ),
              SizedBox(
                height: 32,
              ),
              _bomttonView(),
            ],
          ),
        ),
      ),
    );
  }

  // Widget _bankTypelistView() {
  //   return StreamBuilder(
  //     stream: _bloc.sendBankTypeData,
  //     initialData: _bankWidgetEntity.spinnerList,
  //     builder: (BuildContext contexts, AsyncSnapshot<Object> snapshot) {
  //       Object object = snapshot.data;
  //       if (object is List<IdNameEntity>) {
  //         _bankWidgetEntity.spinnerList?.clear();
  //         _bankWidgetEntity.spinnerList
  //           ..add(CommunitySeletionResultEntity()
  //             ..name = '请选择'
  //             ..id = '');
  //         object.forEach((element) {
  //           _bankWidgetEntity.spinnerList.add(CommunitySeletionResultEntity()
  //             ..id = element.id
  //             ..name = element.name);
  //         });
  //       }
  //       return WidgetUtils.showSpinner(
  //         _bankWidgetEntity,
  //         stateCallback: (date) {
  //           setState(() {
  //             _bankWidgetEntity.spinnerValue = date;
  //           });
  //         },
  //       );
  //     },
  //   );
  // }

  Widget _bomttonView() {
    return ButtonProgressView.crateCupertinoView('确认转换', cupertinoCall: () {
      Map<String, dynamic> data = {};

      data['id'] = '';
      data['userId'] = BaseConstant.userId;
      data['name'] = BaseConstant.name;
      data['idCard'] = BaseConstant.idCard;
      data['bankType'] = 'N' ==
              Utils.getSpinnerId(
                  _zfbWidgetEntity.spinnerList, _zfbWidgetEntity.spinnerValue)
          ? ''
          : 'BT_ZFB';
      data['remark'] = '';
      data['ownerName'] = BaseConstant.name;
      data['ownerPhone'] = BaseConstant.phone;
      // data['beDefault'] = ObjectUtil.isEmptyString(_mrWidgetEntity.spinnerValue)
      //     ? 'N'
      //     : Utils.getSpinnerId(
      //         _mrWidgetEntity.spinnerList, _mrWidgetEntity.spinnerValue);
      // _bloc.addBankDate.add(data);
    });
  }

  @override
  void dispose() {
    _jeWidgetEntity.controller?.clear();
    super.dispose();
  }
}
